home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / ROADS15.ARJ / BOOKENDS.C < prev    next >
C/C++ Source or Header  |  1993-12-23  |  2KB  |  98 lines

  1. #define BOOKENDS_C
  2.  
  3. #include <stdio.h>
  4. #include <fastgraf.h>
  5. #include <alloc.h>
  6. #include <stdlib.h>
  7. #include "roads.h"
  8. #include "fx.h"         /* FOR FADING */
  9. #include "version.h"    /* FOR HEADER */
  10.  
  11. extern int far *topography;      /* BACKGROUND TILE LIST (ARRAY) */
  12. extern int far *terrain;      /* FOREGROUND TILE LIST (ARRAY) */
  13. extern int viewpage;           /* CURRENTLY VIEWED PAGE */
  14.  
  15. int startup_vmode=-1;   /* STARTUP VIDEO MODE TO RETURN TO AT PROGRAM END */
  16.  
  17. /*
  18.  *
  19.  * Initializes/Sets-up the video mode and paging.
  20.  *
  21.  */
  22. void init_video (void)
  23. {
  24.             /* INITIALIZE VIDEO MODE */
  25.     if (fg_testmode (VMODE, VPAGES)==0)
  26.     {
  27.         printf ("Sorry, your video card does not support mode %d.\n", VMODE);
  28.         exit (1);
  29.     }
  30.  
  31.     startup_vmode=fg_getmode();
  32.     fg_setcolor(0);
  33.     fg_setmode (VMODE);
  34.     fg_erase();
  35.  
  36.         /* SETUP SPRITE IMAGES */
  37.     fg_setpage (TILEPAGE);
  38.     fg_erase();
  39.     fg_showgif (IMAGES, 0);
  40.     fg_setpage (viewpage);
  41.     fg_erase();
  42.     fg_tcdefine (0,1); /* TREAT COLOR 0 AS TRANSPARENT */
  43. }
  44.  
  45. /*
  46.  *
  47.  * "Officially" shuts down the program.  Restores video, frees
  48.  * allocated data including fonts, unhooks Sound Blaster,
  49.  * and (optionally) exits with a message and errorcode
  50.  *
  51.  */
  52. void program_shutdown (char *msg, int errcode)
  53. {
  54.     fg_kbinit(0); /* UNLATCH LOW-LEVEL KEYBOARD HANDLER */
  55.  
  56.         /* FREE DATA */
  57.     if (topography!=NULL) farfree (topography);
  58.     if (terrain!=NULL) farfree (terrain);
  59.  
  60.         /* RESTORE ORIGINAL VIDEO MODE TO USER */
  61.     if (startup_vmode!=-1)
  62.     {
  63.         fade_out_all ();
  64.         fg_setmode (startup_vmode);
  65.         fg_reset();
  66.     }
  67.  
  68.         /* FREE FONTS AND SOUND BLASTER SOMEWHERE IN HERE */
  69.  
  70.     printf (HEADER); /* PRINT HEADER */
  71.  
  72.         /* REPORT MESSAGE */
  73.     if (*msg!=NULL)
  74.         printf ("ROADS:  %s\n", msg);
  75.  
  76.         /* QUIT WITH ERROR CODE, IF SUPPLIED ONE */
  77.     if (errcode!=-1)
  78.         exit (errcode);
  79.  
  80.         /* OTHERWISE, RETURN TO CALLER WHO WILL HANDLE EXITING */
  81.     else return;
  82. }
  83.  
  84. /*
  85.  *
  86.  * Initialize dynamic data, which is freed with program_shutdown()
  87.  *
  88.  */
  89. void init_data (void)
  90. {
  91.     topography=farcalloc (WORLD_TILES_TOTAL,sizeof (int));
  92.     terrain=farcalloc (WORLD_TILES_TOTAL,sizeof (int));
  93.  
  94.     if (topography==NULL || terrain==NULL)
  95.        program_shutdown ("Not enough memory -- It's not my fault, I swear!", 1);
  96. }
  97.  
  98.